package chat;
import java.io.*;
import java.net.*;
import java.util.ArrayList;
import java.util.Scanner;


public class Update {
	Server server;
	String newmessage;

	public Update(){
		try{
			server = new Server(8888);
			server.start();
		}
		catch(IOException e){
			e.printStackTrace();
		}
		
		while(server.isAlive()) {
			Scanner sc = new Scanner(System.in);
			String text = sc.nextLine();
		
		
			try{
				InetAddress myAddress = InetAddress.getLocalHost();
				String hostname = myAddress.getHostName();
				System.out.println(hostname);
			
			if(hostname.equalsIgnoreCase("gandalf")){
				new ChatThread("username", text, "frodo.cs.hendrix.edu", 8888).start();
				System.out.println("Bill is added");
			}
			
			if(hostname.equalsIgnoreCase("frodo")){
				new ChatThread("username", text, "gandalf.cs.hendrix.edu", 8888).start();
				System.out.println("ShadowFax is added");
			}
			}
			
			catch(IOException e){
			e.printStackTrace();
			} 
		
		}
		
	}
	
	
	public static void main(String[] args)
	{		
			new Update();
		
	}
}
